package com.icms.web.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.icms.modo.User;
import com.icms.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService u ;
	
	private Map<String, User> maps = new HashMap<String, User>() ;
	
	public UserController() {
		maps.put("1", new User("1", "张三", "男", new Date())) ;
		maps.put("2", new User("2", "李四", "女", new Date())) ;
		maps.put("3", new User("3", "王八", "男", new Date())) ;
		maps.put("4", new User("4", "老六", "女", new Date())) ;
	}

	@RequestMapping(value={"/", "index"})
	public String index(){
		u.say();
		return "index" ;
	}
	
	@RequestMapping(value="/show", method=RequestMethod.GET)
	public String show(Model mode) {
		mode.addAttribute("users", maps) ;
		return "show" ;
	}
	
	@RequestMapping(value="/datagrid", method=RequestMethod.GET)
	@ResponseBody
	public Map<String, User> datagrid() {
		return maps ;
	}
	
	@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
	@ResponseBody
	public User get(@PathVariable String id) {
		return maps.get(id) ;
	}
	
	@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
	public String user(@PathVariable String id) {
		maps.remove(id) ;
		return "index" ;
	}
	
	@RequestMapping(value="/say", method=RequestMethod.GET)
	@ResponseBody
	public void say(){
		System.out.println("你好！");
	}

}
